import random
from selenium import webdriver
import time
from selenium.webdriver.support.ui import Select
class OA:
    def __init__(self):
        dr = webdriver.Firefox(firefox_binary=r'D:\SOFTWARE\FireFox\firefox.exe',
                                        executable_path=r'E:\WoNiu\geckodriver.exe')
        dr.get('http://localhost/smeoa/index.php/login/')
        dr.maximize_window()
        self.dr = dr
        dr.implicitly_wait(1)
    def login(self):
        dr = self.dr
        dr.find_element_by_id('emp_no').send_keys('admin')
        dr.find_element_by_id('password').send_keys('admin')
        dr.find_element_by_css_selector('input.btn.btn-sm.btn-primary.col-10').click()
    def daily(self):
        dr = self.dr
        dr.find_element_by_xpath('//div[@id="navbar-collapse-6"]/ul/a[7]').click()
        dr.find_element_by_xpath('//a[contains(text(),"所有任务")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"等我接受的任务")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"我部门的任务")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"不知让谁处理的任务")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"未完成的任务")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"已完成的任务")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"我发布的任务")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"我指派的任务")]').click()
        dr.find_element_by_name('keyword').send_keys('rec')
        dr.find_element_by_xpath('//form[@id="form_search"]/div/div/a').click()
        dr.find_element_by_id('toggle_adv_search_icon').click()
        dr.find_element_by_id('li_name').send_keys('abc')
        dr.find_element_by_id('eq_user_name').send_keys('rec')
        dr.find_element_by_xpath('//div[2]/div/input').send_keys('123')
        dr.find_element_by_name('be_create_time').click()
        dr.find_element_by_xpath('//tr[4]/td[3]').click()
        dr.find_element_by_name('en_create_time').click()
        dr.find_element_by_xpath('//tr[3]/td[3]').click()
        dr.find_element_by_xpath('//div[2]/a').click()
    def relation(self):
        dr = self.dr
        dr.find_element_by_xpath('//a[8]/i').click()
        dr.find_element_by_xpath('//div[2]/div/div/ul/li/a/span').click()
        dr.find_element_by_xpath('//li/ul/li/a/span').click()
        dr.find_element_by_xpath('//li/ul/li[2]/a/span').click()
        dr.find_element_by_xpath('//li[2]/ul/li/a/span').click()
        dr.find_element_by_xpath('//li[2]/ul/li[2]/a/span').click()
        dr.find_element_by_xpath('//li/ul/li[3]/a/span').click()
        dr.find_element_by_xpath('//li[3]/ul/li[2]/a/span').click()
        dr.find_element_by_xpath('//li[4]/a/span').click()
        dr.find_element_by_xpath('//li[5]/a/span').click()
        dr.find_element_by_xpath('//li[6]/a/span').click()
        dr.find_element_by_xpath('//li[7]/a/span').click()
        dr.find_element_by_xpath('//li[2]/a/span').click()#客户
        dr.find_element_by_xpath('//a/b').click()#管理
        dr.find_element_by_link_text('管理组').click()#管理组
        dr.find_element_by_id('name').send_keys('abc')
        dr.find_element_by_xpath('//span/button').click()#选择父节点
        dr.switch_to.frame(dr.find_element_by_class_name('myFrame'))#切换焦点
        # dr.find_element_by_xpath('//a').click()#确定
        # dr.find_element_by_xpath('//div[3]/div/div[2]/div').click()# ×
        # li=dr.find_elements_by_class_name('fa fa-angle-right level1')#随机选择*
        # print(li)
        # ele = random.choice(li)
        # ele.click()
        time.sleep(2)
        dr.find_element_by_xpath('//span').click()
        dr.find_element_by_xpath('//a[contains(text(),"确定")]').click()
        # dr.find_element_by_xpath('//a[contains(text(),"关闭")]').click()
        dr.switch_to.default_content()
        dr.find_element_by_id('sort').send_keys('123')
        Select(dr.find_element_by_id('is_del')).select_by_value('0')#下拉菜单启用
        dr.find_element_by_xpath('//textarea[@id="remark"]').send_keys('content')
        dr.find_element_by_xpath('//a[contains(text(),"新增")]')
        # dr.find_element_by_xpath('//a[contains(text(),"保存")]').click()
        # l1=dr.find_elements_by_class_name('fa fa-angle-right level1')#随机选择*
        # ele = random.choice(l1)
        # ele.click()
        # dr.find_element_by_xpath('//div/div[3]/div/div/ul/li/a/span').click()
        dr.find_element_by_xpath('//a[contains(text(),"删除")]').click()
        dr.find_element_by_xpath('//button[2]').click()
        dr.find_element_by_xpath('//a[contains(text(),"返回")]').click()
        dr.find_element_by_xpath('//li[3]/a/span').click()
        dr.find_element_by_xpath('//a[contains(text(),"管理")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"导入")]').click()
        dr.find_element_by_name('uploadfile').send_keys('E:\\WoNiu\\img\\test.xlsx')
        dr.find_element_by_xpath('//div/input').click()
        # dr.find_element_by_xpath('//ul[@id="left_menu"]/li[3]/a/span').click()
        dr.find_element_by_xpath('//a[contains(text(),"管理")]').click()
        dr.find_element_by_link_text('管理组').click()#管理组
        dr.find_element_by_id('name').send_keys('abc')
        dr.find_element_by_xpath('//span/button').click()#选择父节点
        dr.switch_to.frame(dr.find_element_by_class_name('myFrame'))#切换焦点
        dr.find_element_by_xpath('//span').click()
        dr.find_element_by_xpath('//a').click()#确定
        # dr.find_element_by_xpath('//div[3]/div/div[2]/div').click()# ×
        # li=dr.find_elements_by_class_name('fa fa-angle-right level1')#随机选择*
        # ele = random.choice(li)
        # ele.click()
        dr.find_element_by_xpath('//a[contains(text(),"关闭")]').click()
        dr.switch_to.default_content()#再次切换焦点
        dr.find_element_by_id('sort').send_keys('123')
        Select(dr.find_element_by_id('is_del')).select_by_value('0')#下拉菜单启用
        dr.find_element_by_xpath('//textarea[@id="remark"]').send_keys('content')
        dr.find_element_by_xpath('//a[contains(text(),"保存")]').click()
        l1=dr.find_elements_by_class_name('fa fa-angle-right level1')#随机选择*
        ele = random.choice(l1)
        ele.click()
        dr.find_element_by_xpath('//a[contains(text(),"删除")]').click()
        dr.find_element_by_xpath('//a[contains(text(),"返回")]').click()
        #dr.find_element_by_xpath('//a[contains(text(),"导出")]').click()P195
        dr.find_element_by_xpath('//a[contains(text(),"新建")]').click()
        dr.find_element_by_id('name').send_keys('1')
        dr.find_element_by_id('short').send_keys('1')
        dr.find_element_by_id('account').send_keys('1')
        dr.find_element_by_id('tax_no').send_keys('1')
        dr.find_element_by_id('address').send_keys('1')
        dr.find_element_by_id('contact').send_keys('1')
        dr.find_element_by_id('email').send_keys('1')
        dr.find_element_by_id('mobile_tel').send_keys('1')
        dr.find_element_by_xpath('//div[9]/div/input').send_keys('1')
        dr.find_element_by_id('fax').send_keys('1')
        dr.find_element_by_id('im').send_keys('1')
        dr.find_element_by_xpath('//textarea').send_keys('1')
        dr.find_element_by_xpath('//input[@value="保存"]').click()
        dr.find_element_by_xpath('//input[@value="取消"]').click()
        dr.find_element_by_xpath('//div[2]/a').click()
        dr.find_element_by_xpath('//label/span').click()
        dr.find_element_by_xpath('//input[@value="应用"]').click()
        dr.find_element_by_xpath('//div[2]/a').click()
        dr.find_element_by_xpath('//input[@value="新组"]').click()
        dr.find_element_by_xpath('//li[4]/input').send_keys('1')
        dr.find_element_by_xpath('//input[@value="应用"]').click()
        dr.find_element_by_xpath('//a[contains(text(),"删除")]').click()
        dr.find_element_by_name('id[]').click()
        dr.find_element_by_xpath('//div[2]/button').click()
        dr.find_element_by_xpath('//a[contains(text(),"删除")]').click()
        dr.find_element_by_xpath('//button[2]').click()
    # def personal(self):
    #     dr = self.dr




























if __name__== "__main__":#格式化
    ag = OA()
    ag.login()
    ag.daily()
    ag.relation()
